package com.etcn.common.interceptor;

import ch.qos.logback.classic.Logger;
import com.etcn.common.utils.UserUtil;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 身份认证过滤器,获取网关传递的身份信息
 *
 * @author guozc
 */
public class IdentityAuthenticationInterceptor implements HandlerInterceptor {
    Logger log = (Logger) LoggerFactory.getLogger(IdentityAuthenticationInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String memberId = request.getHeader("memberId");
        UserUtil.set(memberId);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
    }

}
